/*     */ package com.infoservice.schedule.generator;
/*     */ 
/*     */ import com.infoservice.po3.POFactory;
/*     */ import com.infoservice.po3.POFactoryBuilder;
/*     */ import com.infoservice.po3.core.context.POContext;
/*     */ import com.infoservice.schedule.Constant;
/*     */ import com.infoservice.schedule.po.pos.TaskPO;
/*     */ import com.infoservice.schedule.util.TaskUtils;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Calendar;
/*     */ import java.util.Date;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class GenOnlyOneTask extends TaskGenerator
/*     */ {
/*     */   public GenOnlyOneTask(TaskPlanInfo tpInfo, TaskPO tk)
/*     */   {
/*  38 */     super(tpInfo, tk);
/*     */   }
/*     */ 
/*     */   public void fixTask()
/*     */   {
/*  46 */     Calendar cur = TaskUtils.getCalendar();
/*  47 */     Date planStartTime = getNextExcTime();
/*  48 */     if ((this.tpInfo.getPlanIgnoreFlag().intValue() == 1) && (planStartTime.getTime() <= cur.getTimeInMillis()))
/*     */       try {
/*  50 */         POFactory factory = POFactoryBuilder.getInstance();
/*  51 */         TaskPO taskpo = new TaskPO();
/*  52 */         taskpo.setTaskId(this.tpInfo.getTaskId());
/*  53 */         taskpo.setPlanId(this.tpInfo.getPlanId());
/*  54 */         taskpo.setIgnoreFlag(this.tpInfo.getPlanIgnoreFlag());
/*  55 */         taskpo.setMarker(Integer.valueOf(0));
/*  56 */         taskpo.setExecuteType(this.tpInfo.getTaskManual());
/*  57 */         taskpo.setRunType(this.tpInfo.getPlanRunType());
/*  58 */         taskpo.setStartTimeout(this.tpInfo.getPlanStartTimeout());
/*  59 */         taskpo.setP1value(this.tpInfo.getP1value());
/*  60 */         taskpo.setP2value(this.tpInfo.getP2value());
/*  61 */         taskpo.setP3value(this.tpInfo.getP3value());
/*  62 */         taskpo.setP4value(this.tpInfo.getP4value());
/*  63 */         taskpo.setP5value(this.tpInfo.getP5value());
/*  64 */         taskpo.setLogId(factory.getLongPK(taskpo));
/*  65 */         taskpo.setPlanStartTime(planStartTime);
/*  66 */         factory.insert(taskpo);
/*  67 */         this.logger.info("任务编号==" + this.tpInfo.getTaskId() + "，计划编号===" + this.tpInfo.getPlanId() + "，类型===" + this.tpInfo.getPlanRepeatType() + "，计划执行时间===" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(planStartTime));
/*     */       } finally {
/*     */         try {
/*  70 */           POContext.endTxn(true);
/*  71 */           setTaskPO(planStartTime);
/*     */         } catch (Throwable t) {
/*  73 */           POContext.endTxn(false);
/*  74 */           this.logger.error(t.getMessage(), t);
/*     */         }
/*     */         try {
/*  77 */           POContext.cleanTxn();
/*     */         } catch (Throwable t) {
/*  79 */           this.logger.error(t.getMessage(), t);
/*     */         }
/*     */       }
/*     */   }
/*     */ 
/*     */   public long getDelayTime()
/*     */   {
/*  90 */     Calendar cur = TaskUtils.getCalendar();
/*  91 */     return getNextExcTime().getTime() <= cur.getTimeInMillis() ? 0L : getNextExcTime().getTime() - cur.getTimeInMillis() - Constant.TASK_GEN_AHEAD_TIME;
/*     */   }
/*     */ 
/*     */   public long getPeriodTime()
/*     */   {
/* 100 */     return 0L;
/*     */   }
/*     */ 
/*     */   public void run()
/*     */   {
/* 108 */     genTask();
/*     */   }
/*     */ 
/*     */   public void genTask()
/*     */   {
/* 116 */     Date planStartDate = getNextExcTime();
/* 117 */     if ((this.tk == null) && (TaskUtils.checkTimeRange(planStartDate, this.tpInfo.getPlanStart(), this.tpInfo.getPlanEnd()))) {
/*     */       try {
/* 119 */         POFactory factory = POFactoryBuilder.getInstance();
/* 120 */         TaskPO taskpo = new TaskPO();
/* 121 */         taskpo.setTaskId(this.tpInfo.getTaskId());
/* 122 */         taskpo.setPlanId(this.tpInfo.getPlanId());
/* 123 */         taskpo.setIgnoreFlag(this.tpInfo.getPlanIgnoreFlag());
/* 124 */         taskpo.setMarker(Integer.valueOf(0));
/* 125 */         taskpo.setExecuteType(this.tpInfo.getTaskManual());
/* 126 */         taskpo.setRunType(this.tpInfo.getPlanRunType());
/* 127 */         taskpo.setStartTimeout(this.tpInfo.getPlanStartTimeout());
/* 128 */         taskpo.setP1value(this.tpInfo.getP1value());
/* 129 */         taskpo.setP2value(this.tpInfo.getP2value());
/* 130 */         taskpo.setP3value(this.tpInfo.getP3value());
/* 131 */         taskpo.setP4value(this.tpInfo.getP4value());
/* 132 */         taskpo.setP5value(this.tpInfo.getP5value());
/* 133 */         taskpo.setLogId(factory.getLongPK(taskpo));
/* 134 */         taskpo.setPlanStartTime(planStartDate);
/* 135 */         factory.insert(taskpo);
/* 136 */         this.logger.info("任务编号==" + this.tpInfo.getTaskId() + "，计划编号===" + this.tpInfo.getPlanId() + "，类型===" + this.tpInfo.getPlanRepeatType() + "，计划执行时间===" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(planStartDate));
/*     */       } finally {
/*     */         try {
/* 139 */           POContext.endTxn(true);
/* 140 */           setTaskPO(planStartDate);
/*     */         } catch (Throwable t) {
/* 142 */           POContext.endTxn(false);
/* 143 */           this.logger.error("generator only one task error!" + t.getMessage(), t);
/*     */         }
/*     */         try {
/* 146 */           POContext.cleanTxn();
/*     */         } catch (Throwable t) {
/* 148 */           this.logger.error(t.getMessage(), t);
/*     */         }
/*     */       }
/*     */       try
/*     */       {
/* 146 */         POContext.cleanTxn();
/*     */       } catch (Throwable t) {
/* 148 */         this.logger.error(t.getMessage(), t);
/*     */       }
/*     */     }
/*     */     else {
/* 152 */       return;
/*     */     }
/*     */   }
/*     */ 
/*     */   public Date getNextExcTime()
/*     */   {
/* 160 */     Calendar start = TaskUtils.getCalendar();
/* 161 */     String[] pattern = this.tpInfo.getPlanPattern().split("-");
/* 162 */     start.set(1, Integer.parseInt(pattern[0]));
/* 163 */     start.set(2, Integer.parseInt(pattern[1]) - 1);
/* 164 */     start.set(5, Integer.parseInt(pattern[2]));
/* 165 */     String[] startTime = this.tpInfo.getPlanStart().split(":");
/* 166 */     start.set(11, Integer.parseInt(startTime[0]));
/* 167 */     start.set(12, Integer.parseInt(startTime[1]));
/* 168 */     return start.getTime();
/*     */   }
/*     */ 
/*     */   public void removeTaskPlan()
/*     */   {
/* 176 */     cancel();
/*     */   }
/*     */ 
/*     */   public int getIgnoreTimes()
/*     */   {
/* 185 */     return 0;
/*     */   }
/*     */ 
/*     */   public void setTaskPO(Date planStartTime)
/*     */   {
/* 193 */     if (this.tk == null) {
/* 194 */       this.tk = new TaskPO();
/* 195 */       this.tk.setPlanStartTime(planStartTime);
/*     */     } else {
/* 197 */       this.tk.setPlanStartTime(planStartTime);
/*     */     }
/*     */   }
/*     */ 
/*     */   public Date getEndDate()
/*     */   {
/* 206 */     Calendar endTime = TaskUtils.getCalendar();
/* 207 */     String[] pattern = this.tpInfo.getPlanPattern().split("-");
/* 208 */     endTime.set(1, Integer.parseInt(pattern[0]));
/* 209 */     endTime.set(2, Integer.parseInt(pattern[1]) - 1);
/* 210 */     endTime.set(5, Integer.parseInt(pattern[2]));
/* 211 */     String[] end = this.tpInfo.getPlanEnd().split(":");
/* 212 */     endTime.set(11, Integer.parseInt(end[0]));
/* 213 */     endTime.set(12, Integer.parseInt(end[1]));
/* 214 */     return endTime.getTime();
/*     */   }
/*     */ 
/*     */   public long getInterval()
/*     */   {
/* 223 */     return 0L;
/*     */   }
/*     */ 
/*     */   public Date getStartDate()
/*     */   {
/* 231 */     Calendar start = TaskUtils.getCalendar();
/* 232 */     String[] pattern = this.tpInfo.getPlanPattern().split("-");
/* 233 */     start.set(1, Integer.parseInt(pattern[0]));
/* 234 */     start.set(2, Integer.parseInt(pattern[1]) - 1);
/* 235 */     start.set(5, Integer.parseInt(pattern[2]));
/* 236 */     String[] end = this.tpInfo.getPlanStart().split(":");
/* 237 */     start.set(11, Integer.parseInt(end[0]));
/* 238 */     start.set(12, Integer.parseInt(end[1]));
/* 239 */     return start.getTime();
/*     */   }
/*     */ }

/* Location:           D:\Workspace\Work\ASMP_DE\lib\frame3\InfoSchedule_1.0.03.jar
 * Qualified Name:     com.infoservice.schedule.generator.GenOnlyOneTask
 * JD-Core Version:    0.6.0
 */